/*
 * @Author: szx
 * @Date: 2022-05-25 14:28:35
 * @LastEditTime: 2022-05-25 14:33:58
 * @Description:
 * @FilePath: \leetcode\400-499\467\467.js
 */
/**
 * @param {string} p
 * @return {number}
 */
var findSubstringInWraproundString = function (p) {
    const dp = new Array(26).fill(0);
    let k = 0;
    for (let i = 0; i < p.length; ++i) {
        if (i > 0 && (p[i].charCodeAt() - p.charCodeAt(i - 1) + 26) % 26 === 1) {
            // 字符之差为 1 或 -25
            ++k;
        } else {
            k = 1;
        }
        dp[p.charCodeAt(i) - 97] = Math.max(dp[p[i].charCodeAt() - 97], k);
    }
    return dp.reduce((a, b) => a + b);
};
